//
//  JYNetWorkManager.swift
//  JYCalculate
//
//  Created by 何治军 on 2018/10/29.
//  Copyright © 2018 何治军. All rights reserved.
//

import UIKit
import AFNetworking

class JYNetWorkManager: NSObject {
    static let  sharedInstance:JYNetWorkManager = JYNetWorkManager()
    private let sessionManager = AFHTTPSessionManager()
    override init() {
        super.init()
//        let sessionManager = AFHTTPSessionManager()
        sessionManager.requestSerializer = AFJSONRequestSerializer()
        sessionManager.responseSerializer.acceptableContentTypes = ["application/json","text/html", "text/json", "text/javascript","text/plain","image/gif"]
        sessionManager.requestSerializer.timeoutInterval = 90
    }
    
    func getTheUrl(url:String , parameters:Any? ,completion:((String,Any?)->Void)? = nil) {
        sessionManager.get(url, parameters: parameters, progress: nil, success: { (tast, responseObject) in
            if responseObject != nil {
                 let dic = responseObject as AnyObject
                if let result = dic["result"] {
                    completion?(dic["reason"] as! String,result as Any)
                }else{
                     completion?("网路错误",nil)
                }
            }else{
                completion?("网路错误",nil)
            }
            
        }) { (tast, error) in
            print(error)
        }
    }
}
